<?php

/*****************************************************************************
 * Copyright (C) 2009 Gwathuirim
 *
 * This is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 3 of the License, or (at your option) any later
 * version.
 *
 * This is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Public License for more details
 *
 * To obtain a copy of the GNU General Public License, please see
 * <http://www.gnu.org.licenses/>
 *****************************************************************************/
 
require_once('class.reportmail.php');
 
class SingleReportMail extends ReportMail {

	var $report;

	public function __construct($report, $environmentVars) {
		parent::__construct($environmentVars);
		
		$this->report = $report;
	}
	
	public function send($recipient) {
		$mail = $this->setupMail($recipient);
		
		$subjectTpl = $this->createTemplate($this->environmentVars->language."/singleReportMailSubject.tpl");
		$mail->Subject = $subjectTpl->fetch();
		
		$bodyTpl = $this->createTemplate($this->environmentVars->language."/singleReportMail.tpl");
		$reportTpl = $this->createTemplate($this->environmentVars->language."/".$this->report->type."Report.tpl");
		
		$bodyTpl->set('reportContent', $reportTpl);
		$mail->Body = $bodyTpl->fetch();
		
		$result = new stdClass();
		if ($mail->Send()) {
			$result->code = CODE_MAILSENDOK;
			return $result;;
		} else {
			$result->code = CODE_MAILSENDFAILED;
			$result->message = $mail->ErrorInfo;
			return $result;
		}
	}
	
	public function createTemplate($filename) {
		$resultTpl = parent::createTemplate($filename);
		$resultTpl->set('report', $this->report);
		
		return $resultTpl;
	}
}
 
?>